﻿using LoveEat.API.Write.Applications.Commands.Aquaculture;
using LoveEat.Domain.Aquaculture;
using LoveEat.ErrorCode;
using LoveEat.Infrastructure.Interfaces;
using MediatR;

namespace LoveEat.API.Write.Applications.CommandHandlers.Aquaculture
{
    public class AddAquacultureCommandHandler : IRequestHandler<AddAquacultureCommand, APIResult<int>>
    {
        private readonly IBaseRespository<AquacultureModel> aquaRep;

        public AddAquacultureCommandHandler(IBaseRespository<AquacultureModel> aquaRep)
        {
            this.aquaRep = aquaRep;
        }

        public async Task<APIResult<int>> Handle(AddAquacultureCommand request, CancellationToken cancellationToken)
        {
            APIResult<int> result = new APIResult<int>();
            result.Code=APIResultCode.添加成功;
            result.Message=APIResultCode.添加成功.ToString();


            AquacultureModel aqua=new AquacultureModel();
            aqua.variety=request.variety;
            aqua.Source = request.Source;
            aqua.Days=request.Days;
            aqua.Brand=request.Brand;
            aqua.Manager=request.Manager;
            aqua.Releasedate=request.Releasedate;
            aqua.Farm=request.Farm;
            aqua.Charge=request.Charge;
            aqua.Numberstock=request.Numberstock;
            aqua.IsDelete=false;
            await aquaRep.AddAsync(aqua);





            return await Task.FromResult(result);
        }
    }
}
